<!--
* description: 新增编辑-驳回
-->
<template>
  <section class="editBigAreaInfo">
    <el-dialog
      v-dialogDrag
      :close-on-click-modal="false"
      :title="textMap[popupsState]"
      :append-to-body="true"
      :visible.sync="curPopupsVisible"
      width="50%"
      @close="closeEdit"
    >
      <dialogHeader
        slot="title"
        :title="textMap[popupsState]"
        :style-type="$store.state.app.dialogType"
      />

      <div class="filter-container filter-params">
        <el-row ref="vailComponentList" :gutter="26">
          <component
            :is="comp.component"
            v-for="comp in tableComponents.filter((o) => o.isMust === true)"
            :ref="comp.isRequire ? comp.isRequire + comp.compKey : comp.compKey"
            :key="comp.compKey"
            :validrule="comp.validrule"
            :code-field="comp.codeField"
            :text-field="comp.textField"
            :popups-key="comp.compKey"
            :parent-fileds="comp.parentFileds || ''"
            :code="formField[comp.codeField]"
            :disabled="comp.disabled"
            :is-require="comp.isRequire"
            :is-mul="comp.isMul"
            :span="comp.span || 8"
            :label-name="comp.labelName"
            :lookuptype="comp.lookuptype"
            :date-options-type="comp.dateOptionsType"
            @changeCode="getComponentCode"
          />
        </el-row>
      </div>

      <div slot="footer" class="dialog-footer">
        <el-button
          v-for="comp in tableButtons"
          :key="comp.compKey"
          :type="comp.type"
          :icon="comp.icon"
          @click="comp.clickEvent"
          >{{ comp.text }}</el-button
        >
      </div>
    </el-dialog>
  </section>
</template>
<script>
import { formMixins } from "@/components/mixins/formMixins";
import request from "@/utils/request";
import api from "@/api/pa/apiBranchWarehouse";

export default {
  components: {
    dialogHeader: () => import("@/components/dialogHeader"),
    mixButton: () => import("@/components/basicComponent/mixButton"),
  },

  // 组件混入对象
  mixins: [formMixins],

  props: {
    popupsVisible: { type: Boolean, default: false },
    selectiondata: { type: Array, default: [] },
  },

  data() {
    const viewPageCode = "bigAreaInfo-edit";
    return {
      // 动态组件-按钮
      tableButtons: [
        {
          compKey: "btnKey1",
          type: "primary",
          size: "small",
          icon: "iconfont  icon-preservation",
          clickEvent: () => this.save(),
          text: this.$t("sys.button.save") /* 保存*/,
          position: "right",
        },
        {
          compKey: "btnKey2",
          type: "",
          size: "small",
          icon: "iconfont  icon-cancel",
          clickEvent: () => this.close(),
          text: this.$t("sys.button.cancel"), // 取消
        },
      ],

      // 动态组件-查询条件
      tableComponents:
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode] &&
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode].formComponents
          .length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[viewPageCode].formComponents
          : [
              {
                compKey: "compKey1",
                labelName: "审核意见",
                codeField: "remark",
                component: () =>
                  import("@/components/org/commonInput/textareaInput"),
                type: "inputText",
                isMust: true,
                isRequire: true,
                span: 24,
              },
            ],

      // 标题
      textMap: {
        edit: "驳回意见",
        add: "通过意见",
      },

      // 表单数据（无需赋值，由混入对象赋值）
      formField: this.$utils.getFormField(
        this,
        {
          remark: "",
        },
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode]
      ),
    };
  },
  methods: {
    // 关闭弹窗
    // handleClose(done) {
    //   this.$confirm('还未保存，确认关闭窗口？')
    //     .then(_ => {
    //       this.$emit('update:curPopupsVisible', false)
    //       done()
    //     })
    //     .catch(_ => {})
    // },
    closeEdit() {
      this.$emit("close", false);
    },
    // 新增/编辑保存按钮
    save() {
      const that = this;
      this.$utils.validataMoth(this, "validpopup");
      if (this.valid) {
        this.approvedAndjection()
      }
    },

    approvedAndjection() {
      let that=this
      that.selectiondata.forEach((element) => {
        element.auditMark = that.formField.remark;
      });
      let urlApi = "";
      if (that.popupsState === "edit") {
        urlApi = api.updateRejection.APIUrl;
      } else {
        urlApi = api.updateApproved.APIUrl;
      }
      request({
        url: urlApi,
        method: "post",
        data: that.selectiondata,
      }).then((res) => {
        that.$message.success(res.msg);
        that.curPopupsVisible=false
        that.$parent.queryTable(1);    
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.promptSpan {
  position: absolute;
  bottom: 26px;
  right: 335px;
  color: #e70020;
}
</style>

